jQuery.fn.news = function (contextPath) {
	var panel = this;
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xhr.open("GET", contextPath + "/seam/resource/news",true);
	//xhr.open("GET","http://localhost:8080/c/journal/get_articles?templateId=10242&amp;languageId=en&amp;orderByCol=display-date&amp;delta=3",true);
	xhr.onreadystatechange = function(){
		if (xhr.readyState==4){
			if (xhr.status==200){
				displayNews(panel,xhr);
			}else{
				//alert("Error...");
			}
			
			}
	}
	xhr.send(null);
}

function displayNews(panel,xhr){
		//panel = document.getElementById("newspanel");
		var xmlDoc=xhr.responseXML;
		var results = xmlDoc.getElementsByTagName("result");
		var resultHTML = "";
		var validCnt = 0;
		for(var j=0;j<results.length;j++){
			var result=results[j];
			var elems =result.getElementsByTagName("dynamic-element");
			var title="";
			var body="";
			var image="";
			var displayDate="";
			for(var i=0;i<elems.length;i++){
				var elem = elems[i];
				var atri = elem.getAttribute("name");
				if(atri == "title"){
					title = elem.getElementsByTagName("dynamic-content")[0].firstChild.data;
					continue;
				}
				if(atri == "image"){
					image = elem.getElementsByTagName("dynamic-content")[0].firstChild.data;
					continue;
				}
				if(atri == "body"){
					body = elem.getElementsByTagName("dynamic-content")[0].firstChild.data;
					continue;
				}
				if(atri == "reserved-article-display-date"){
					displayDate = elem.getElementsByTagName("dynamic-content")[0].firstChild.data;
					continue;
				}
			}
			//if(image.length==0)continue;
			var imageTag = getImageTag(image);
			if(++validCnt==1){
				if(body.length>290)body=body.substring(0,290)+"...";
				panel.append("<div  class='title1'><a href='/portal/web/ctg/home'><h4>"+title+"</h4></a><div class='left'><a href='/portal/web/ctg/home'>"+imageTag+ "</a></div><div class='body1'><p>" + body + "</p></div><br class='clearb'/></div>");
			}else{
				if(title.length>20)title=title.substring(0,20)+"..."; 
				if(body.length>140)body=body.substring(0,140)+"..."; 
				panel.append("<div class='title2'><a href='/portal/web/ctg/home'><h4>"+title+"</h4></a><a href='/portal/web/ctg/home'>"+imageTag+ "</a><div class='body2'>" + body + "</div></div>");
			}
			if(validCnt==4)break;
			
		}
		
		}
		function getImageTag(image){
			if(image.length<1)return "";
			var imgUrl = image;
			if(image.indexOf("@image_path@")!=-1 && image.indexOf("@group_id@")!=-1){
				imgUrl = "/portal/image"+image.substring("@image_path@".length,image.indexOf("@group_id@"))+"273"+image.substring(image.lastIndexOf("@"));
				//imgUrl = "/image"+image.substring("@image_path@".length,image.indexOf("@group_id@"))+"273"+image.substring(image.lastIndexOf("@"));
			}else if(image.indexOf("@image_path@")!=-1){
				imgUrl = "/portal/image"+image.substring("@image_path@".length);
				//imgUrl = "/image"+image.substring("@image_path@".length);
			}else if(image.indexOf("@group_id@")!=-1){
				imgUrl = "/portal/"+image.substring(image.indexOf("@group_id@"),"@group_id@".length-1)+"273"+image.substring(image.lastIndexOf("@"));
				//imgUrl = "/"+image.substring(image.indexOf("@group_id@"),"@group_id@".length-1)+"273"+image.substring(image.lastIndexOf("@"));
			}
			return "<img src='http://www.crotouristguide.com"+imgUrl+"' style='margin-right: 5px; width:100px;height:70px;'/>";
	}